<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>留言板</title>
	<link rel="stylesheet" type="text/css" href="./style/style.css" />
	<script type="text/javascript">
	function check(){
		var author  = document.getElementsByName("message.uname")[0].value;
		var message = document.getElementsByName("message.content")[0].value;
		var errorMsg= "";
		if(author==""|| author=="请输入您的名字") {
			errorMsg += "作者不能为空";
		}
		if(message=="") {
			errorMsg += "\n内容不能为空";
		}
		if(message.length>500) {
			errorMsg += "\n内容长度不能大于500";
		}
		if(author.length>20) {
			errorMsg += "\n作者名长度不能大于20";
		}
		if(errorMsg!=""){
			alert(errorMsg);
			return false;
		}
	}
	
	function checkName_mouseOut(){ 
		if(document.getElementsByName("message.uname")[0].value==''){
			document.getElementsByName("message.uname")[0].value='请输入您的名字';
			document.getElementsByName("message.uname")[0].className='gray input';
		}
	}
	
	function checkName_mouseOver(){ 
		if(document.getElementsByName("message.uname")[0].value=='请输入您的名字'){
			document.getElementsByName("message.uname")[0].value='';
			document.getElementsByName("message.uname")[0].className='input';
		}
	}
	
	function turnPage(p){
		var author = document.forms[0].author.value;
		var message = document.forms[0].message.value;
		window.location.href="turnPage.jsp?page="+p+"&author="+author+"&message="+message;
	}
	</script>
  </head>
  <body>
  <div align="center">
	<h1>小小留言板</h1>
	<!-- 内容开始 -->
<s:if test="mlist != null">
	<s:iterator value="mlist" status="status">
    <div>
    	<div class="t c">
	    	<div class="t2" align="left">&nbsp;作者：<s:property value="uname"/></div>
	    	<div align="right">${status.count + (pageNow-1)*4}#&nbsp;</div>
	    	<div class="t1 tipad" align="left"><s:property value="content"/></div>
	    	<div class="gray" align="right">发表：<s:date name="createtime" format="yyyy年MM月dd日 HH:mm:ss"/></div>
	    </div>
    </div>
    </s:iterator>
 </s:if>
<s:if test="mlist.size == 0">
 <div>
		<h1 style="color: red">没有更多内容啦！<br/>赶快给小伙伴留言吧！<br/>点击"上一页"返回查看<br/>点击"下一页"从头浏览...</h1>
 </div>
</s:if>
    <!-- 内容结束 -->
    
    <div class="tipad" style="width:500px" align="right">
		<input class="btn1" type="button" value="上一页" onclick="window.location.href='message_get?pageNow=${pageNow <= 1 ? 1 : pageNow -1}'" >&nbsp;
		<input class="btn1" type="button" value="下一页" onclick="window.location.href='message_get?pageNow=${empty mlist ? 1 : pageNow+1}'"><br/>&nbsp;
	</div>

    <div style="width:500px" align="left">&nbsp;
	   <form action="message_add" method="post" onSubmit="return check()">
		    <div>用 户 名</div>
		    <div style="position:relative; left:50px; top:-18px">
		    	<input type="text" name="message.uname" class="gray input" value="请输入您的名字" onMouseOver="return checkName_mouseOver()" onMouseOut="return checkName_mouseOut()"/>
		    </div>
		    <div>留言信息</div>
		    <div style="position:relative; left:50px; top:-18px">
		    	<textarea  name="message.content" rows="5" cols="55"></textarea>
		    </div>
	    	<div align="center" style="position:relative;left:-50px;width:500px">
	    	<input type="submit" value="提 交" class="btn"/>
	    	</div>
	    </form>
    </div>
  </div>
  </body>
</html>